import { Controller } from "../../mvc/core/Controller";
import { ICrossAdoreController } from "./interfaces/ICrossAdoreController";
import { IView } from "../../mvc/interfaces/IView";
import { CrossAdoreModule } from "../../../modules/CrossAdoreModule";
import { HintIcon } from "../view/uiIconBtn/HintIcon";
import { ImagesConst } from "../resource/ImagesConst";
import { UiHintIconView } from "../view/uiIconBtn/UiHintIconView";
import { EffectManager } from "../manager/EffectManager";
import { UIIconEvent } from "../view/uiIconBtn/UIIconEvent";
import { Alert } from "../../../com/mui/controls/Alert";
import { Language } from "../../../extend/language/Language";
import { ENpcEffect } from "../../../Message/Public/ENpcEffect";
import { AIManager } from "../scene/ai/AIManager";
import { AIType } from "../scene/ai/AIType";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { EGateCommand } from "../../../Message/Command/EGateCommand";
import { EPublicCommand } from "../../../Message/Command/EPublicCommand";
import { DataEvent } from "../events/DataEvent";
import { ICrossAdoreModule } from "../../../modules/interfaces/ICrossAdoreModule";
import { SystemSetter } from "../view/system/SystemSetter";
import { GameProxy } from "../mvc/GameProxy";
import { MessageBlock } from "../../../Framework/MQ/MessageBlock";
import { SCrossWorshipInfo } from "../../../Message/Public/SCrossWorshipInfo";
import { SLookupPlayerReply } from "../../../Message/Game/SLookupPlayerReply";
import { ELottertType } from "../../../Message/Public/ELottertType";
import { ExplorerRumorData } from "../view/treasure/ExplorerRumorData";
import { SPublicNotice } from "../../../Message/Public/SPublicNotice";
import { EShowArea } from "../../../Message/Public/EShowArea";
type int = number;
//class CrossAdoreController
    
    export  class CrossAdoreController extends Controller implements ICrossAdoreController
    {
       

        protected /* override */ initView(): IView
        {
            if (this._crossAdoreModule == null) 
            {
                this._crossAdoreModule = new CrossAdoreModule();
            }
            return this._crossAdoreModule;
        }

        /* internal  */showCrossAdoreIcon(): void
        {
            if (this._crossAdoreIcon == null) 
            {
                this._crossAdoreIcon = new HintIcon(ImagesConst.CrossAdore, true);
                this._crossAdoreIcon.addEventListener(flash.events.MouseEvent.CLICK, this.onCrossAdoreIconClickHandler);
            }
            if (!this._crossAdoreIcon.parent) 
            {
                UiHintIconView.instance.addHintIcon(this._crossAdoreIcon);
            }
            return;
        }

        /* internal  */hideHintIcon(): void
        {
            if (this._crossAdoreIcon && this._crossAdoreIcon.parent) 
            {
                EffectManager.glowFilterUnReg(this._crossAdoreIcon);
                this._crossAdoreIcon.dispatchEvent(new UIIconEvent(UIIconEvent.RemoveIcon));
            }
            return;
        }

        /* internal  */onCrossAdoreIconClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Alert.okLabel = Language.getString(36359);
            Alert.yesLabel = Language.getString(36360);
            Alert.buttonWidth = 70;
            Alert.showCloseBtn = true;
            var loc1=Language.getString(36361);
            Alert.show(loc1, Language.getString(36362), Alert.YES | Alert.OK, null, this.onCloseHandler);
            return;
        }

        /* internal  */onCloseHandler(arg1: int): void
        {
            var loc1=cache.scene.getNpcByEffect(ENpcEffect._ENpcEffectOpenWorshipView);
            if (arg1 != Alert.OK) 
            {
                if (arg1 == Alert.YES) 
                {
                    AIManager.onAutoPathAIControl(loc1);
                }
            }
            else 
            {
                AIManager.onAIControl(loc1, AIType.AI_Convey);
            }
            this.showCrossAdoreIcon();
            return;
        }

        protected /* override */ initServer(): void
        {
            Dispatcher.addEventListener(EventName.CrossAdoreNpcReq, this.onCrossAdoreNpcReqHandler);
            Dispatcher.addEventListener(EventName.CrossAdoreToAdore, this.onCrossAdoreToAdoreHandler);
            Dispatcher.addEventListener(EventName.CrossAdoreGetAdoreNum, this.onCrossAdoreGetAdoreNumHandler);
            Dispatcher.addEventListener(EventName.CrossAdoreGetPersonNumSuccess, this.onGetPersonNumSuccessHandler);
            NetDispatcher.addCmdListener(EGateCommand._ECmdGateWorshipRewardBroadCast, this.onWorshipRewardBroadCastHandler);
            NetDispatcher.addCmdListener(EGateCommand._ECmdGateWorshipDummyNum, this.onWorshipDummyNumHandler);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicSTChatelainInfoBack, this.onSTChatelainInfoHandler);
            Dispatcher.addEventListener(EventName.TreasureGetRecordsSuccess, this.onGetRecordsSuccessHandler);
            Dispatcher.addEventListener(EventName.TreasureExplorerRumorAdd, this.onExplorerRumorAddHandler);
            Dispatcher.addEventListener(EventName.CrossMainCity_Enter, this.onCrossMainCityEnterHandler);
            Dispatcher.addEventListener(EventName.CrossMainCity_Leave, this.onCrossMainCityLeaveHandler);
            Dispatcher.addEventListener(EventName.SysSettingSuccess, this.onSysSettingSuccessHandler);
            return;
        }

        /* internal  */onCrossAdoreNpcReqHandler(arg1: DataEvent): void
        {
            view.show();
            (view as ICrossAdoreModule).guideAdore(SystemSetter.currentSetter.isComplsteCrossAdore);
            return;
        }

        /* internal  */onCrossAdoreToAdoreHandler(arg1: DataEvent): void
        {
            GameProxy.chatProxy.worshipShengTianSanto(arg1.data as int);
            if (!SystemSetter.currentSetter.isComplsteCrossAdore) 
            {
                SystemSetter.localSetter.isComplsteCrossAdore = true;
                Dispatcher.dispatchEvent(new DataEvent(EventName.Sys_SaveInfoNotShowInWindow));
                this.hideHintIcon();
                (view as ICrossAdoreModule).guideAdore(SystemSetter.currentSetter.isComplsteCrossAdore);
            }
            return;
        }

        /* internal  */onCrossAdoreGetAdoreNumHandler(arg1: DataEvent): void
        {
            GameProxy.chatProxy.getTotalAndPersonWorshipNum();
            return;
        }

        /* internal  */onGetPersonNumSuccessHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as int;
            var loc2=arg1.isResult as Boolean;
            if (this._crossAdoreModule && !this._crossAdoreModule.isHide) 
            {
                this._crossAdoreModule.setAdoreNum(loc1);
                if (loc2) 
                {
                    this._crossAdoreModule.adoreSuccess();
                }
            }
            return;
        }

        /* internal  */onWorshipRewardBroadCastHandler(arg1: MessageBlock): void
        {
            return;
        }

        /* internal  */onWorshipDummyNumHandler(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SCrossWorshipInfo;
            if (!(this._crossAdoreModule == null) && !this._crossAdoreModule.isHide) 
            {
                this._crossAdoreModule.updateAdoreNum(loc1.dummyNum);
            }
            return;
        }

        /* internal  */onSTChatelainInfoHandler(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SLookupPlayerReply;
            if (!(this._crossAdoreModule == null) && !this._crossAdoreModule.isHide) 
            {
                this._crossAdoreModule.updateSTChatelainInfo(loc1);
            }
            return;
        }

        /* internal  */onGetRecordsSuccessHandler(arg1: DataEvent): void
        {
            var loc2=null;
            var loc1=arg1.data["type"] as int;
            if (loc1 == ELottertType._ELotteryWorshipShengtian) 
            {
                loc2 = arg1.data["records"] as Array<any>;
                ExplorerRumorData.noticeMap[loc1] = loc2;
                if (!(this._crossAdoreModule == null) && !this._crossAdoreModule.isHide) 
                {
                    this._crossAdoreModule.updateAdoreBroadcast();
                }
            }
            return;
        }

        /* internal  */onExplorerRumorAddHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as SPublicNotice;
            if (loc1.area & EShowArea._EShowAreaExplorer && loc1.code == ELottertType._ELotteryWorshipShengtian) 
            {
                ExplorerRumorData.setNoticeMap([loc1], loc1.code);
                if (!(this._crossAdoreModule == null) && !this._crossAdoreModule.isHide) 
                {
                    this._crossAdoreModule.updateAdoreBroadcast();
                }
            }
            return;
        }

        /* internal  */onCrossMainCityEnterHandler(arg1: DataEvent): void
        {
            if (!SystemSetter.currentSetter.isComplsteCrossAdore) 
            {
                this.showCrossAdoreIcon();
            }
            return;
        }

        /* internal  */onCrossMainCityLeaveHandler(arg1: DataEvent): void
        {
            this.hideHintIcon();
            return;
        }

        /* internal  */onSysSettingSuccessHandler(arg1: DataEvent): void
        {
            if (SystemSetter.currentSetter.isComplsteCrossAdore) 
            {
                if (this._crossAdoreModule && !this._crossAdoreModule.isHide) 
                {
                    (view as ICrossAdoreModule).guideAdore(SystemSetter.currentSetter.isComplsteCrossAdore);
                }
                if (this._crossAdoreIcon && !this._crossAdoreIcon.isHide) 
                {
                    this.hideHintIcon();
                }
            }
            return;
        }

        private /* var */_crossAdoreModule: ICrossAdoreModule;

        private /* var */_crossAdoreIcon: HintIcon;
    }
